# -*- coding: utf-8 -*-

from pymongo import MongoClient as mgClient

from autoscrapy import config

class mongoClient(object):

    def __init__(self, name):
        client = mgClient(config.mongo_url)
        self._db = client[name]

    @property
    def db(self):
        return self._db

    def add_entrys(self, entrys):
        for _e in entrys:
            collection = _e.pop('collection')
            self.db[collection].insert_one(_e)

    def find_entry_by_fields(self, fields):
        collection = fields.pop('collection')
        return self.db[collection].find(fields)

    def del_entrys_by_field(self, field):
        collection = field.pop('collection')
        return self.db[collection].delete_many(field)


